import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:app/src/http/bean/wroks/attachment_bean.dart';
import 'package:app/src/http/bean/wroks/special_clauses.dart';
import 'package:app/src/http/url.dart';

///订单审核条目信息
class OrderItemInfo extends BaseBean {
  ///Id编号
  String? ItemId = "";

  ///条目编号
  String? OrderItemId = "";

  ///客户下单宽度
  String? ItemWidth_Customers = "";

  ///客户下单高度
  String? ItemHeight_Customers = "";

  ///宽
  String? ItemWidth = "";

  ///高
  String? ItemHeight = "";

  ///数量
  String? ItemNum = "";

  ///矩形面积
  String? JxArea = "";

  ///实际面积
  String? AbnormityTrueArea = "";

  ///结算面积
  String? JsArea = "";

  ///周长
  String? Girth = "";

  ///总面积
  String? JxAreaSum = "";

  ///安装编号
  String? ItemCode = "";

  ///打孔数量
  String? DrillNum = "";

  ///挖缺个数
  String? DigNum = "";

  ///错片类型
  String? DistinctSizeTypeName = "";

  ///宽左
  String? AdgeThree = "";

  ///宽右
  String? AdgeFour = "";

  ///高上
  String? AdgeOne = "";

  ///高下
  String? AdgeTwo = "";

  ///另收/片
  String? OtherAmount = "";

  ///他合计/片
  String? SumOtherAmount = "";

  ///备注
  String? ItemIntro = "";

  ///分组
  String? ItemGroupCode = "";

  ///图号
  String? ItemDrawingNo = "";

  ///图形
  _ItemDrawingShape? ItemDrawingShape = null;

  ///打开小图标
  void openIcon(BuildContext context) {
    FileUtils.openFile(context, Url.getFileUrl(ItemDrawingShape?.getIconUrl()));
  }

  ///打开大图片
  void openImage(BuildContext context) {
    FileUtils.openFile(context, Url.getFileUrl(ItemDrawingShape?.getImagePathUrl()));
  }

  ///附件
  List<Attachment>? ItemFile = null;

  Attachment? getItemFile() {
    if (ItemFile != null && ItemFile!.length > 0) {
      return ItemFile![0];
    }
    return null;
  }

  ///玻璃层次
  List<OrderItem>? OrderItemList = null;

  ///特殊加工条目
  List<SpecialItemInfo>? SpecialItemList = null;

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    ItemId = json['ItemId']?.toString() ?? "";
    OrderItemId = json['OrderItemId']?.toString() ?? "";
    ItemWidth_Customers = json['ItemWidth_Customers']?.toString() ?? "";
    ItemHeight_Customers = json['ItemHeight_Customers']?.toString() ?? "";
    ItemWidth = json['ItemWidth']?.toString() ?? "";
    ItemHeight = json['ItemHeight']?.toString() ?? "";
    ItemNum = json['ItemNum']?.toString() ?? "";
    JxArea = json['JxArea']?.toString() ?? "";
    AbnormityTrueArea = json['AbnormityTrueArea']?.toString() ?? "";
    JsArea = json['JsArea']?.toString() ?? "";
    Girth = json['Girth']?.toString() ?? "";
    JxAreaSum = json['JxAreaSum']?.toString() ?? "";
    ItemCode = json['ItemCode']?.toString() ?? "";
    DrillNum = json['DrillNum']?.toString() ?? "";
    DigNum = json['DigNum']?.toString() ?? "";
    DistinctSizeTypeName = json['DistinctSizeTypeName']?.toString() ?? "";
    AdgeThree = json['AdgeThree']?.toString() ?? "";
    AdgeFour = json['AdgeFour']?.toString() ?? "";
    AdgeOne = json['AdgeOne']?.toString() ?? "";
    AdgeTwo = json['AdgeTwo']?.toString() ?? "";
    OtherAmount = json['OtherAmount']?.toString() ?? "";
    SumOtherAmount = json['SumOtherAmount']?.toString() ?? "";
    ItemIntro = json['ItemIntro']?.toString() ?? "";
    ItemGroupCode = json['ItemGroupCode']?.toString() ?? "";
    ItemDrawingNo = json['ItemDrawingNo']?.toString() ?? "";
    ItemDrawingShape =
        setGenericFromJson(json, 'ItemDrawingShape', _ItemDrawingShape(), "");
    ItemFile =
        setGenericFromJson(json, 'ItemFile', <Attachment>[], Attachment());
    OrderItemList =
        setGenericFromJson(json, 'OrderItemList', <OrderItem>[], OrderItem());
    SpecialItemList = setGenericFromJson(
        json, 'SpecialItemList', <SpecialItemInfo>[], SpecialItemInfo());
  }

  @override
  instance() {
    // TODO: implement instance
    return OrderItemInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["ItemId"] = ItemId;
    map["OrderItemId"] = OrderItemId;
    map["ItemWidth_Customers"] = ItemWidth_Customers;
    map["ItemHeight_Customers"] = ItemHeight_Customers;
    map["ItemWidth"] = ItemWidth;
    map["ItemHeight"] = ItemHeight;
    map["ItemNum"] = ItemNum;
    map["JxArea"] = JxArea;
    map["AbnormityTrueArea"] = AbnormityTrueArea;
    map["JsArea"] = JsArea;
    map["Girth"] = Girth;
    map["JxAreaSum"] = JxAreaSum;
    map["ItemCode"] = ItemCode;
    map["DrillNum"] = DrillNum;
    map["DigNum"] = DigNum;
    map["DistinctSizeTypeName"] = DistinctSizeTypeName;
    map["AdgeThree"] = AdgeThree;
    map["AdgeFour"] = AdgeFour;
    map["AdgeOne"] = AdgeOne;
    map["AdgeTwo"] = AdgeTwo;
    map["OtherAmount"] = OtherAmount;
    map["SumOtherAmount"] = SumOtherAmount;
    map["ItemIntro"] = ItemIntro;
    map["ItemGroupCode"] = ItemGroupCode;
    map["ItemDrawingNo"] = ItemDrawingNo;
    map["ItemDrawingShape"] = ItemDrawingShape;
    map["ItemFile"] = ItemFile;
    map["OrderItemList"] = OrderItemList;
    map["SpecialItemList"] = SpecialItemList;
    return map;
  }

// ///打开文件
// void open(BuildContext context) {
//   FileUtils.openFile(context, Url.getFileUrl(FilePatch));
// }
//
// ///文件分享
// void share(BuildContext context) {
//   FileUtils.shareFile(context, Url.getFileUrl(FilePatch));
// }

  ///fixme 以下是自己添加的字段。
  bool isOpenAn = false; //是否张开，订单条目

}

///订单条目2;特殊加工项
class SpecialItemInfo extends BaseBean {
  ///标题名称
  String? SpecialName = "";

  ///标题数量
  String? SpecialNum = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    SpecialName = json['SpecialName']?.toString() ?? "";
    SpecialNum = json['SpecialNum']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return SpecialItemInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["SpecialName"] = SpecialName;
    map["SpecialNum"] = SpecialNum;
    return map;
  }
}

//"OrderItemList": [{
//    "ItemLayer": "1",
//    "ListWidth": "1000.0",
//    "ListHeight": "1000.0"
//}]
///玻璃层次
class OrderItem extends BaseBean {
  ///第几层
  String? ItemLayer = "";

  ///宽度
  String? ListWidth = "";

  ///高度
  String? ListHeight = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    ItemLayer = json['ItemLayer']?.toString() ?? "";
    ListWidth = json['ListWidth']?.toString() ?? "";
    ListHeight = json['ListHeight']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return OrderItem();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["ItemLayer"] = ItemLayer;
    map["ListWidth"] = ListWidth;
    map["ListHeight"] = ListHeight;
    return map;
  }
}

//{
//    "scalPoint": [{
//    "x": 172.29428995098505,
//    "y": 327.70571004901495
//},
//    {
//        "x": 406.60858978760194,
//        "y": 327.70571004901495
//    },
//    {
//        "x": 172.29428995098505,
//        "y": 93.391410212398057
//    }
//    ],
//    "zPoint": [{
//    "x": 289.45143986929349,
//    "y": 327.70571004901495
//},
//    {
//        "x": 289.45143986929349,
//        "y": 210.54856013070651
//    },
//    {
//        "x": 172.29428995098505,
//        "y": 210.54856013070651
//    }
//    ],
//    "side": [
//    100,
//    141.42,
//    100
//    ],
//    "primitivePoint": [{
//    "x": 30,
//    "y": 30
//},
//    {
//        "x": 130,
//        "y": 30
//    },
//    {
//        "x": 30,
//        "y": 130
//    }
//    ],
//    "Line": [{
//    "BeginPoint": {
//    "x": 147.29428995098505,
//    "y": 327.70571004901495
//},
//    "EndPoint": {
//    "x": 147.29428995098505,
//    "y": 93.391410212398057
//}
//},
//    {
//        "BeginPoint": {
//        "x": 172.29428995098505,
//        "y": 352.70571004901495
//    },
//        "EndPoint": {
//        "x": 406.60858978760194,
//        "y": 352.70571004901495
//    }
//    }
//    ],
//    "Label": [{
//    "Point": {
//    "x": 147.29428995098505,
//    "y": 210.54856013070651
//},
//    "text": "100"
//},
//    {
//        "Point": {
//        "x": 289.45143986929349,
//        "y": 352.70571004901495
//    },
//        "text": "100"
//    }
//    ],
//    "shape": null,
//    "Pieces": 12,
//    "Itemcode": "",
//    "ImagePath": "../Images/UploadCADImage/132606211307988138.png",
//    "Index": null,
//    "ShapeType": "Triangle",
//    "ShapeCode": 4,
//    "SideCount": 3,
//    "Origin": {
//    "x": 30,
//    "y": 30
//},
//    "Radius": 0,
//    "Parameter": "100,100",
//    "ico": "/Images/Graphics/GraphicsIco/Triangle4.png",
//    "Width": 100,
//    "Height": 100,
//    "Area": 0,
//    "primitiveOriginList": null,
//    "primitiveOrigin": null,
//    "primitiveRadius": 0
//}
///图形
class _ItemDrawingShape extends BaseBean {
  ///大图标;直接显示这个即可。原图好像是500x500像素的尺寸。
  String? ImagePath = "";

  ///获取大图标地址
  String? getImagePathUrl() {
    return Url.getFileUrl(ImagePath);
  }

  ///小图标
  String? ico = "";

  ///获取小图标地址
  String? getIconUrl() {
    return Url.getFileUrl(ico);
  }

  List<_Point>? scalPoint = null;
  List<_Point>? zPoint = null;
  List<String>? side = null;
  List<_Point>? primitivePoint = null;
  List<_Line>? Line = null;
  List<_Label>? Label = null;
  _Point? Origin = null;
  String? shape = "";
  String? Pieces = "";
  String? Itemcode = "";
  String? Index = "";
  String? ShapeType = "";
  String? ShapeCode = "";
  String? SideCount = "";
  String? Radius = "";
  String? Parameter = "";
  String? Width = "";
  String? Height = "";
  String? Area = "";
  String? primitiveOriginList = "";
  String? primitiveOrigin = "";
  String? primitiveRadius = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    ImagePath = json['ImagePath']?.toString() ?? "";
    ico = json['ico']?.toString() ?? "";
    scalPoint = setGenericFromJson(json, 'scalPoint', <_Point>[], _Point());
    zPoint = setGenericFromJson(json, 'zPoint', <_Point>[], _Point());
    side = setGenericFromJson(json, 'side', <String>[], "");
    primitivePoint =
        setGenericFromJson(json, 'primitivePoint', <_Point>[], _Point());
    Line = setGenericFromJson(json, 'Line', <_Line>[], _Line());
    Label = setGenericFromJson(json, 'Label', <_Label>[], _Label());
    Origin = setGenericFromJson(json, 'Origin', _Point(), "");
    shape = json['shape']?.toString() ?? "";
    Pieces = json['Pieces']?.toString() ?? "";
    Itemcode = json['Itemcode']?.toString() ?? "";
    Index = json['Index']?.toString() ?? "";
    ShapeType = json['ShapeType']?.toString() ?? "";
    ShapeCode = json['ShapeCode']?.toString() ?? "";
    SideCount = json['SideCount']?.toString() ?? "";
    Radius = json['Radius']?.toString() ?? "";
    Parameter = json['Parameter']?.toString() ?? "";
    Width = json['Width']?.toString() ?? "";
    Height = json['Height']?.toString() ?? "";
    Area = json['Area']?.toString() ?? "";
    primitiveOriginList = json['primitiveOriginList']?.toString() ?? "";
    primitiveOrigin = json['primitiveOrigin']?.toString() ?? "";
    primitiveRadius = json['primitiveRadius']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return _ItemDrawingShape();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["ImagePath"] = ImagePath;
    map["ico"] = ico;
    map["scalPoint"] = scalPoint;
    map["zPoint"] = zPoint;
    map["side"] = side;
    map["primitivePoint"] = primitivePoint;
    map["Line"] = Line;
    map["Label"] = Label;
    map["Origin"] = Origin;
    map["shape"] = shape;
    map["Pieces"] = Pieces;
    map["Itemcode"] = Itemcode;
    map["Index"] = Index;
    map["ShapeType"] = Index;
    map["ShapeCode"] = ShapeCode;
    map["SideCount"] = SideCount;
    map["Radius"] = Radius;
    map["Parameter"] = Parameter;
    map["Width"] = Width;
    map["Height"] = Height;
    map["Area"] = Area;
    map["primitiveOriginList"] = primitiveOriginList;
    map["primitiveOrigin"] = primitiveOrigin;
    map["primitiveRadius"] = primitiveRadius;
    return map;
  }
}

///点
class _Point extends BaseBean {
  String? x = "";
  String? y = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    x = json['x']?.toString() ?? "";
    y = json['y']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return _Point();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["x"] = x;
    map["y"] = y;
    return map;
  }
}

///线
class _Line extends BaseBean {
  _Point? BeginPoint = null;
  _Point? EndPoint = null;

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    BeginPoint = setGenericFromJson(json, 'BeginPoint', _Point(), "");
    EndPoint = setGenericFromJson(json, 'EndPoint', _Point(), "");
  }

  @override
  instance() {
    // TODO: implement instance
    return _Line();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["BeginPoint"] = BeginPoint;
    map["EndPoint"] = EndPoint;
    return map;
  }
}

//标签
class _Label extends BaseBean {
  _Point? Point = null;
  String? text = null;

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    Point = setGenericFromJson(json, 'Point', _Point(), "");
    text = json['text']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return _Label();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Point"] = Point;
    map["text"] = text;
    return map;
  }
}
